<template>
  <!--    功能区-->
  <div>
    <div class="first">
      <h1 class="title_sub gn">功能区：</h1>
      <span v-if="showUpdateStatusBtn">
        <el-button
          type="primary"
          size="small"
          v-if="delivery"
          @click="putUpdateStatus(3)"
          >标记已交件</el-button
        >
      </span>
      <span v-if="showUpdateStatusBtn">
        <el-button
          type="primary"
          size="small"
          v-if="delivery"
          @click="putUpdateStatus(-2)"
          >标记交件失败</el-button
        >
      </span>

      <span v-if="!status">
        <span v-if="showReturnedStatusList">
          <el-button
            type="primary"
            size="small"
            v-if="pending"
            @click="putUpdateStatus(4)"
            >标记为已放款</el-button
          >
        </span>
      </span>
      <el-button
        type="danger"
        size="small"
        v-if="markUpdate == 1 && showMarkUpdate"
        @click="markUpdateFun"
        >处理此订单更新</el-button
      >
      <el-button
        type="danger"
        size="small"
        v-if="markUpdate == 0 && showMarkUpdate"
        >我已处理此订单更新</el-button
      >
    </div>
  </div>
</template>

<script>
import {
  putUpdateStatus,
  markUpdate,
  getProductUrl
} from "../../../src/assets/js/api";
import { checkPermiss } from "../../assets/js/utlis";
export default {
  name: "FunctionalAreas",
  props: ["delivery", "pending", "orderNumber", "released"],
  created() {
    this.golbalPermissions = localStorage.getItem("permissions").split(",");
    this.status = eval(this.$route.query.status);
    this.Restatus = eval(this.$route.query.Restatus);
    this.findProductUrl(this.orderNumber);
  },
  data() {
    return {
      status: null,
      Restatus: null,
      markForm: {
        orderNumber: this.orderNumber,
        markUpdate: 0
      },
      golbalPermissions: [],
      ProductUrl: "",
      markUpdate:""
    };
  },
  computed: {
    //订单更新按钮
    showMarkUpdate: function() {
      return checkPermiss("business:order:markUpdate", this.golbalPermissions);
    },
    // 待交件-标记(已交件,交件失败)按钮
    showUpdateStatusBtn: function() {
      return checkPermiss(
        "business:order:updateStatus",
        this.golbalPermissions
      );
    },
    //标记已归档按钮
    showReturnedStatusList: function() {
      return checkPermiss(
        "business:order:returnedStatusList",
        this.golbalPermissions
      );
    },
    //TODO：财务信息添加按钮(标记已放款，标记放款失败TODO)
    showChargeBtn: function() {
      return checkPermiss("business:upForm:charge", this.golbalPermissions);
    }
  },
  methods: {
    /**
     * 标记已交件 statusId ==3
     * 交件失败 statusId ==-2
     * 标记已放款 statusId ==4
     * 放款失败 statusId ==-3
     * 标记为已归档 statusId ==5
     * 标记为已归档 statusId ==7
     */
    putUpdateStatus(statusId) {
      //标记已交件
      putUpdateStatus({
        orderNumber: this.orderNumber,
        statusId: statusId
      }).then(res => {
        if (res.code == 200) {
          this.$message({
            message: res.message,
            type: "success"
          });
          this.$router.replace({ path: this.ProductUrl });
        } else {
          this.$message({
            message: res.message,
            type: "error"
          });
        }
      });
    },
    //根据订单查询路由path路径
    findProductUrl(orderNumber) {
      getProductUrl({
        orderNumber: orderNumber
      }).then(res => {
        this.ProductUrl = res.data.productUrl;
        this.markUpdate = res.data.markUpdate
      });
    },
    markUpdateFun() {
      markUpdate(this.markForm).then(res => {
        if (res.code == 200) {
          this.$message({
            message: res.message,
            type: "success"
          });
          this.$router.replace({ path: this.ProductUrl });
        } else {
          this.$message({
            message: res.message,
            type: "error"
          });
        }
      });
    }
  }
};
</script>

<style scoped type="less">
.first {
  line-height: 35px;
  text-align: left;
  overflow: hidden;
}
h1 {
  float: left;
}
span {
  margin-right: 10px;
}
</style>
